<template>
  <header class="header">
    <h1>todos</h1>
    <input id="toggle-all" class="toggle-all" type="checkbox" v-model="isAll">
    <label for="toggle-all"></label>
    <input
      class="new-todo"
      placeholder="输入任务名称-回车确认"
      autofocus
      v-model="task"
      @keydown.enter='addTaskFn'
    />
  </header>
</template>

<script>
export default {
  data(){
    return{
      task:'',
      list:[]
    }
  },
  methods:{
    addTaskFn(){
      // this.list=[this.list,this.task]
      this.$store.commit('getTasklist', {name:this.task,isShow:false})
      this.task=''
    }
  },
  computed:{
    isAll:{
      set(val){
        return this.$store.state.taskList.forEach((item) => item.isShow = val)
      },
      get(){

        return this.$store.state.taskList.every((item) => item.isShow === true)
      }
    }
  }
}
</script>
